package com.atguigu.controller;

import com.atguigu.entity.UserInfo;
import com.atguigu.result.Result;
import com.atguigu.service.UserFellowService;
import com.atguigu.vo.UserFollowVo;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/userFollow")
public class UserFollowController {

    @DubboReference
    private UserFellowService userFellowService;

    @GetMapping("/auth/follow/{houseId}")
    @ResponseBody
    public Result follow(@PathVariable() Long houseId, HttpServletRequest request){
        HttpSession session = request.getSession();
        UserInfo userInfo = (UserInfo) session.getAttribute("USER");
        userFellowService.follow(userInfo.getId(),houseId);
        return Result.ok();
    }
   /*   axios.get('/userFollow/auth/list/'+pageNum+'/'+this.page.pageSize).t*/

    @GetMapping(value = "/auth/list/{pageNum}/{pageSize}")
        @ResponseBody
        public Result findListPage(@PathVariable Integer pageNum,
                @PathVariable Integer pageSize,
                HttpServletRequest request) {
            UserInfo userInfo = (UserInfo)request.getSession().getAttribute("USER");
            Long userId = userInfo.getId();
            PageInfo<UserFollowVo> pageInfo = userFellowService.findListPage(pageNum, pageSize, userId);
            return Result.ok(pageInfo);
    }
    @GetMapping("auth/cancelFollow/{id}")
    @ResponseBody
    public Result cancelFollow(@PathVariable("id") Long id){
        userFellowService.delete(id);
        return Result.ok();
    }
}